package com.xuzimian.globaldemo.spring.springsecurity.config;

import com.xuzimian.globaldemo.spring.springsecurity.service.SpittleService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;

import com.xuzimian.globaldemo.spring.springsecurity.service.ExpressionSecuredSpittleService;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ExpressionSecurityConfig extends GlobalMethodSecurityConfiguration {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //设置用户并配置角色,这里的角色和SecurityContext 里面的角色没有关联
        auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
        auth.inMemoryAuthentication().withUser("user1").password("password1").roles("USER");
    }

    @Bean
    public SpittleService spitterService() {
        return new ExpressionSecuredSpittleService();
    }

}
